<html>
    <head>
        <title>产品修改</title>
        <link href="{$Think.const.ADMIN_CSS_URL}bootstrap.css" rel="stylesheet" />
        <link href="{$Think.const.ADMIN_CSS_URL}lz-style.css" rel="stylesheet" />
        <script src="{$Think.const.ADMIN_JS_URL}jquery.js"></script>
        <script src="{$Think.const.ADMIN_JS_URL}jquery.form.js"></script>
        <script src="{$Think.const.ADMIN_JS_URL}bootstrap.js"></script>
        <script src="{$Think.const.ADMIN_JS_URL}DatePicker/WdatePicker.js"></script>
        <script src="{$Think.const.ADMIN_URL}Ueditor/ueditor.config.js" ></script>
        <script src="{$Think.const.ADMIN_URL}Ueditor/ueditor.all.min.js"></script>
        <script src="{$Think.const.PUBLIC_URL}js/jlz.js"></script>
        <script language="JavaScript">

            $(function () {
                $('#editform').ajaxForm({
                    beforeSubmit: checkForm, // pre-submit callback
                    success: complete, // post-submit callback
                    dataType: 'json'
                });
                function checkForm() {

                    if ('' == $.trim($('#ProductCode').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_PRODUCTCODE}]不能为空').show();
                        return false;
                    }

                    if ('' == $.trim($('#ProductName').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_PRODUCTNAME}]不能为空').show();
                        return false;
                    }

                    if ('' == $.trim($('#BasePrice').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_BASEPRICE}]不能为空').show();
                        return false;
                    }

                    if ('' == $.trim($('#ProductCategoryId').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_PRODUCTCATEGORYID}]不能为空').show();
                        return false;
                    }

                    if ('' == $.trim($('#BrandID').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_BRANDID}]不能为空').show();
                        return false;
                    }

                    if ('' == $.trim($('#ProductIMG').val())) {
                        $('#success').hide();
                        $('#error').html('[{$Think.const.LB_PRODUCTIMG}]不能为空').show();
                        return false;
                    }

                }
                function complete(data) {
                    if (data.status === 1) {
                        $('#error').hide();
                        $('#success').html(data.info).show();
                    } else {
                        $('#success').hide();
                        $('#error').html(data.info).show();
                    }
                }


            });

        </script>

        <style type="text/css">
            .clear {
                clear: both;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="row div_head" >
                <div class=" col-xs-6 col-sm-6 text-primary">
                    {$loction}
                </div>
                <div class="col-xs-6 col-sm-3"></div>
                <div class="col-xs-6 col-sm-3">
                    <a style="text-decoration: none" href="__CONTROLLER__/lst">【返回】</a>
                </div>
            </div>

            <hr />
            <div class="row" >
                <div class=" col-xs-6 col-sm-6 text-primary">
                    产品基础信息
                </div>
            </div>
            <div class="row div_form" >
                <form id="editform" action="__SELF__" method="post">
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="ProductCode" class="control-label">{$Think.const.LB_PRODUCTCODE}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="ProductCode" name="ProductCode" class="form-control" placeholder="{$Think.const.LB_PRODUCTCODE}"  value="{$post.productcode}" maxlength="42"   required />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="ProductName" class="control-label">{$Think.const.LB_PRODUCTNAME}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="ProductName" name="ProductName" class="form-control" placeholder="{$Think.const.LB_PRODUCTNAME}"  value="{$post.productname}" maxlength="100"   required />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="BasePrice" class="control-label">{$Think.const.LB_BASEPRICE}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_number" >
                        <input type="number" id="BasePrice" name="BasePrice" class="form-control" placeholder="{$Think.const.LB_BASEPRICE}"  value="{$post.baseprice}"   required/>
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="ProductCategoryId" class="control-label">{$Think.const.LB_PRODUCTCATEGORYID}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="ProductCategoryId" name="ProductCategoryId" class="form-control" placeholder="{$Think.const.LB_PRODUCTCATEGORYID}"  value="{$post.productcategoryid}" maxlength="42"   required />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="BrandID" class="control-label">{$Think.const.LB_BRANDID}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="BrandID" name="BrandID" class="form-control" placeholder="{$Think.const.LB_BRANDID}"  value="{$post.brandid}" maxlength="42"   required />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 div_required" ><label for="ProductIMG" class="control-label">{$Think.const.LB_PRODUCTIMG}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="ProductIMG" name="ProductIMG" class="form-control" placeholder="{$Think.const.LB_PRODUCTIMG}"  value="{$post.productimg}" maxlength="42"   required />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 " ><label for="ProductSIMG" class="control-label">{$Think.const.LB_PRODUCTSIMG}:</label></div>
                    <div class="col-xs-6 col-sm-3 div_text" >
                        <input type="text" id="ProductSIMG" name="ProductSIMG" class="form-control" placeholder="{$Think.const.LB_PRODUCTSIMG}"  value="{$post.productsimg}" maxlength="42"    />
                    </div>
                    <div class="text-right col-xs-6 col-sm-3 " ><label for="ProductStatus" class="control-label">{$Think.const.LB_PRODUCTSTATUS}:</label></div>
                    <div class="col-xs-6 col-sm-3" >
                        <select id="ProductStatus" name="ProductStatus" class="form-control" value="{$post.productstatus}"   >
                            <option value="" style="display: none"></option>
                            <foreach name="GV_Enum.ProductStatus" item="row" key="k">
                                <if condition="$k eq $post.productstatus ">
                                    <option value="{$k}" selected = "selected" >{$k}-{$row}</option>
                                    <else />
                                    <option value="{$k}" >{$k}-{$row}</option>
                                </if>
                            </foreach>
                        </select>
                    </div>
                    <div class="col-xs-6 col-sm-9">

                    </div>
                    <div class="col-xs-6 col-sm-3">
                        <input type="submit" id="search"  class="btn btn-default" value="修改产品基本信息">
                    </div>

                </form>
            </div>
            <div id="error" class="row text-danger"></div>
            <div id="success" class="row text-success"></div>
            <hr />
            <div class="row " >
                <div class=" col-xs-6 col-sm-6 text-primary">
                    产品属性信息
                </div>
                <div class="col-xs-6 col-sm-3"></div>
                <div   class="col-xs-6 col-sm-3 text-primary">
                    <a id="addproductproperty" style="text-decoration: none" >【新增产品属性】</a>
                    <a id="saveproductproperty" style="text-decoration: none" >【保存产品属性】</a>
                    <script>

                        function delproductproperty(uuid) {

                            $("#" + uuid).remove();
                        }
                        $('#addproductproperty').click(function () {
                            var uuid = guid();
                            $('#productproperty').append('<div id="' + uuid + '" class="productpropertylist"><div class="col-xs-5 col-sm-5 propertyname"><input type="text" class="form-control " placeholder="请输入属性名" value="asd" maxlength="20"/></div><div class="col-xs-5 col-sm-5 propertyvalue"><input type="text"class="form-control " placeholder="请输入属性值" maxlength="20"/></div><div class="col-xs-1 col-sm-1"><button type="button" onclick="delproductproperty(&apos;' + uuid + '&apos;)" class="close" aria-hidden="true">×</button></div></div>'
                                    );
                        });
                        $('#saveproductproperty').click(function () {

                            $('#productproperty').children().each(function () {
                                $(this).children().each(function () {

                                    if ($(this).attr("class").indexOf("propertyname") != -1) {
                                        $(this).children().each(function () {
                                            var aa = $(this)[0].value;
                                            alert(aa);
                                        });
                                    }

                                });
                            });
                        });

                    </script>

                </div>

            </div>

            <div class="row " >
                <ul id="productproperty_tab" class="nav nav-tabs">
                    <li class="active">
                        <a href="#home" data-toggle="tab">菜鸟教程</a>
                    </li>
                    <li>
                        <a id="ios" href="#ios" data-toggle="tab">iOS</a>
                    </li>
                    <li id="addproductpropertytype">
                        <a id="ProductPropertyTypeAdd"  href="#ProductPropertyTypeModal" data-toggle="modal">+</a>
                    </li>
                    <script>
                        $(function () {
                            $.post("__MODULE__/ProductPropertyType/lst", {ProductCode: $('#ProductCode')[0].value},
                                    function (data) {
                                        for (var i in data) {
                                            $('#ios').html(i + data[i]['productpropertytypename']);
                                        }
                                    });
                        });
                    </script>
                    <script>
                        $('#ProductPropertyTypeAdd').click(function () {
                            $('#ProductPropertyTypeID')[0].value = '';
                            $('#ProductPropertyTypeSort')[0].value = '';
                            $('#ProductPropertyTypeName')[0].value = '';
                            $('#ProductPropertyEditType')[0].value = 'I';
                        });
                    </script>
                    <!-- 模态框（Modal） -->
                    <div class="modal fade" id="ProductPropertyTypeModal" >
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title" id="myModalLabel">属性类</h4>
                                </div>
                                <div class="modal-body">
                                    <div class="container">
                                        <div class="row">
                                            <input type="hidden" id="ProductPropertyEditType" name="ProductPropertyEditType"/>
                                            <input type="hidden" id="ProductPropertyTypeID" name="ProductPropertyTypeID"/>
                                            <div class="col-xs-3 col-sm-2 col-md-2 col-lg-2 div_text" >
                                                <input type="number" id="ProductPropertyTypeSort" name="ProductPropertyTypeSort" class="form-control" placeholder="请输入序号" min="1" max="10"/>
                                            </div>
                                            <div class="col-xs-9 col-sm-4 col-md-4 col-lg-4 div_text" >
                                                <input type="text" id="ProductPropertyTypeName" name="ProductPropertyTypeName" class="form-control" placeholder="请输入属性类"   maxlength="20"/>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button id="ProductPropertyTypeSave" type="button" class="btn btn-primary">保存</button>
                                </div>
                                <script>

                                    $('#ProductPropertyTypeSave').click(function () {
                                        if ($('#ProductPropertyEditType')[0].value === 'I') {
                                            var uuid = guid();
                                            $('#ProductPropertyTypeID')[0].value = uuid;
                                            $.post("__MODULE__/ProductPropertyType/add", {ProductCode: $('#ProductCode')[0].value, ProductPropertyTypeID: $('#ProductPropertyTypeID')[0].value, ProductPropertyTypeSort: $('#ProductPropertyTypeSort')[0].value, ProductPropertyTypeName: $('#ProductPropertyTypeName')[0].value},
                                                    function (data) {
                                                        if (data.status === 1) {
                                                            $('#ProductPropertyEditType')[0].value = 'U';
                                                            alert(data.info);
                                                        } else {
                                                            alert(data.info);
                                                        }
                                                    });
                                        } else {
                                            $.post("__MODULE__/ProductPropertyType/edit", {ProductCode: $('#ProductCode')[0].value, ProductPropertyTypeID: $('#ProductPropertyTypeID')[0].value, ProductPropertyTypeSort: $('#ProductPropertyTypeSort')[0].value, ProductPropertyTypeName: $('#ProductPropertyTypeName')[0].value},
                                                    function (data) {
                                                        if (data.status === 1) {
                                                            $('#ProductPropertyEditType')[0].value = 'U';
                                                            alert(data.info);
                                                        } else {
                                                            alert(data.info);
                                                        }
                                                    });
                                        }

                                    });
                                </script>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal -->
                    </div>
                    <script>
                        $(function () {
                            $('#ProductPropertyTypeModal').modal({
                                backdrop: false
                            })
                        });
                    </script>
                    <script>
                        $(function () {
                            $('#ProductPropertyTypeModal').modal('toggle')
                        });
                    </script>

                </ul>

                <div id="productproperty_content" class="tab-content">
                    <div class="tab-pane fade in active" id="home">
                        <p>菜鸟教程是一个提供最新的web技术站点，本站免费提供了建站相关的技术文档，帮助广大web技术爱好者快速入门并建立自己的网站。菜鸟先飞早入行——学的不仅是技术，更是梦想。</p>
                    </div>
                    <div class="tab-pane fade" id="ios">
                        <p>iOS 是一个由苹果公司开发和发布的手机操作系统。最初是于 2007 年首次发布 iPhone、iPod Touch 和 Apple 
                            TV。iOS 派生自 OS X，它们共享 Darwin 基础。OS X 操作系统是用在苹果电脑上，iOS 是苹果的移动版本。</p>
                    </div>
                </div>
            </div>                
            <hr />
            <div class="row " >
                <div class=" col-xs-6 col-sm-6 text-primary">
                    产品规格
                </div>
                <div class="col-xs-6 col-sm-3"></div>
                <div class="col-xs-6 col-sm-3">
                    <a style="text-decoration: none" data-toggle="modal"  href="#myModal">【保存产品规格】</a>
                </div>                
            </div>                
            <hr />
            <div class="row " >
                <div class=" col-xs-6 col-sm-6 text-primary">
                    产品详情信息
                </div>
                <div class="col-xs-6 col-sm-3"></div>
                <div class="col-xs-6 col-sm-3">
                    <a style="text-decoration: none" data-toggle="modal"  href="#myModal">【保存详情信息】</a>
                </div>                
            </div>
            <div class="row " >
                <div>
                    <form name='MyForm' id='MyForm' method='POST' action="__URL_ _/message_insert" >
                        <script id="editor" name="editor" type="text/plain" style="width:1024px;height:300">
                            从数据库中取出文章内容打印到此处！！                            ！
                        </script>
                    </form>
                </div>

                <div id="btns">
                    <div>
                        <button onclick="getAllHtml()">获得整个html的内容</button>
                        <button onclick="getContent()">获得内容</button>
                        <button onclick="setContent()">写入内容</button>
                        <button onclick="setContent(true)">追加内容</button>
                        <button onclick="getContentTxt()">获得纯文本</button>
                        <button onclick="getPlainTxt()">获得带格式的纯文本</button>
                        <button onclick="hasContent()">判断是否有内容</button>
                        <button onclick="setFocus()">使编辑器获得焦点</button>
                    </div>
                    <div>
                        <button onclick="getText()">获得当前选中的文本</button>
                        <button onclick="insertHtml()">插入给定的内容</button>
                        <button id="enable" onclick="setEnabled()">可以编辑</button>
                        <button onclick="setDisabled()">不可编辑</button>
                        <button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
                        <button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
                        <button onclick=" UE.getEditor('editor').setHeight(300)">设置编辑器的高度为300</button>
                    </div>

                </div>
                <div>
                    <button onclick="createEditor()"/>创建编辑器</button>
                    <button onclick="deleteEditor()"/>删除编辑器</button>

                    <button onclick="submitEditor()"/>提交</button>
                </div>
            </div>
            <script type="text/javascript">

                //实例化编辑器
                var ue = UE.getEditor('editor');
                function insertHtml() {
                    var value = prompt('插入html代码', '');
                    ue.execCommand('insertHtml', value)
                }
                function createEditor() {
                    enableBtn();
                    UE.getEditor('editor');
                }
                function getAllHtml() {
                    alert(UE.getEditor('editor').getAllHtml())
                }
                function getContent() {
                    var arr = [];
                    arr.push("使用editor.getContent()方法可以获得编辑器的内容");
                    arr.push("内容为：");
                    arr.push(UE.getEditor('editor').getContent());
                    alert(arr.join("\n"));
                }
                function getPlainTxt() {
                    var arr = [];
                    arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
                    arr.push("内容为：");
                    arr.push(UE.getEditor('editor').getPlainTxt());
                    alert(arr.join('\n'))
                }
                function setContent(isAppendTo) {
                    var arr = [];
                    arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
                    UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
                    alert(arr.join("\n"));
                }
                function setDisabled() {
                    UE.getEditor('editor').setDisabled('fullscreen');
                    disableBtn("enable");
                }

                function setEnabled() {
                    UE.getEditor('editor').setEnabled();
                    enableBtn();
                }

                function getText() {
                    //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
                    var range = UE.getEditor('editor').selection.getRange();
                    range.select();
                    var txt = UE.getEditor('editor').selection.getText();
                    alert(txt)
                }

                function getContentTxt() {
                    var arr = [];
                    arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
                    arr.push("编辑器的纯文本内容为：");
                    arr.push(UE.getEditor('editor').getContentTxt());
                    alert(arr.join("\n"));
                }
                function hasContent() {
                    var arr = [];
                    arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
                    arr.push("判断结果为：");
                    arr.push(UE.getEditor('editor').hasContents());
                    alert(arr.join("\n"));
                }
                function setFocus() {
                    UE.getEditor('editor').focus();
                }
                function deleteEditor() {
                    disableBtn();
                    UE.getEditor('editor').destroy();
                }

                //提交方法
                function submitEditor() {
                    //此处以非空为例
                    if (ue.hasContents()) {
                        ue.sync(); //同步内容
                        document.MyForm.submit();
                    }
                }

                function disableBtn(str) {
                    var div = document.getElementById('btns');
                    var btns = domUtils.getElementsByTagName(div, "button");
                    for (var i = 0, btn; btn = btns[i++]; ) {
                        if (btn.id == str) {
                            domUtils.removeAttributes(btn, ["disabled"]);
                        } else {
                            btn.setAttribute("disabled", "true");
                        }
                    }
                }
                function enableBtn() {
                    var div = document.getElementById('btns');
                    var btns = domUtils.getElementsByTagName(div, "button");
                    for (var i = 0, btn; btn = btns[i++]; ) {
                        domUtils.removeAttributes(btn, ["disabled"]);
                    }
                }

            </script>
        </div>    


    </body>
</html>
